import 'package:flutter/material.dart';
import 'model/post.dart';

//void main() {
//  runApp(
//    App()
//  );
//}

void main() => runApp(App());

//自定义小部件，需要改动继承StatefulWidget；不需要改动StatelessWidget
class App extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
//      home: Hello(),//设置首页
    home: Home(),
      theme: ThemeData(
        primarySwatch: Colors.green,//appbar的颜色
      ),//设置主题
    );
  }
}


class Home extends StatelessWidget{
  Widget _listItemBuilder(BuildContext context,int index){
    return Container(
      color: Colors.white,
      margin: EdgeInsets.all(8.0),
      child: Column(
        children: <Widget>[
          Image.network(posts[index].imageUrl),
          SizedBox(height: 16),
          Text(
            posts[index].title,
            style: Theme.of(context).textTheme.title
          ),
          Text(
            posts[index].author,
            style: Theme.of(context).textTheme.subhead,
          ),
          SizedBox(height: 16,)
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      backgroundColor: Colors.grey[100],
      appBar: AppBar(
        title: Text('nin hao'),//标题
        elevation: 100.0,//阴影大小，默认4.0
      ),//顶部工具栏
//      body: Hello(),
      body: ListView.builder(
        itemCount: posts.length,//设置列表数量
        itemBuilder: _listItemBuilder,
      ),
    );
  }
}

class Hello extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Center(
      child: Text(
        'hello  12',
        textDirection: TextDirection.ltr,
        style: TextStyle(
            fontSize: 40.0,//设置字号
            fontWeight: FontWeight.bold,//文字的样式
            color: Colors.black87
        ),
      ),
    );
  }
}
